﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpChapters_3
{
    class Program
    {
        //private string name;
        //public string Name
        //{
        //    get { return name; }
        //    set { name = value; }
        //}

        //public string Name { get; set; }

        public string Name { get; private set; }

        static void Main()
        {
            int[] array = new int[10];
            int[] array_1 = new[] { 1, 2, 3, 4 };
            int[] array_2 = new int[] { 1, 2, 3, 4 };
            E_Commerce.CreateOrder();

            //匿名对象创建表达式
            var player = new
            {
                Name = "Eadd",
                Score = 3500
            };
            Console.WriteLine("Player name: {0}", player.Name);
            Console.WriteLine("Player score: {0}", player.Score);

            LambdaExample.LambdaPrint();
        }
    }

    #region 电子商务系统订单模型

    public class E_Commerce
    {
        public static void CreateOrder()
        {
            //var customer = new Customer();
            //customer.Name = "Jon";
            //customer.Address = "UK";

            //var item1 = new OrderItem();
            //item1.ItemId = "abcd123";
            //item1.Quantity = 1;
            //var item2 = new OrderItem();
            //item2.ItemId = "fghi456";
            //item2.Quantity = 2;

            ////创建订单
            //var order = new Order();
            //order.OrderId = "xyz";
            //order.Customer = customer;
            //order.Items.Add(item1);
            //order.Items.Add(item2);

            //使用对象初始化器和集合初始化器来创建和添加订单
            //对象初始化器
            var order = new Order
            {
                OrderId = "xyz",
                Customer = new Customer { Name = "Jon", Address = "UK" },

                //items是一个list，此处使用集合初始化器，编译器自动转换为 items.Add();
                Items =
                {
                    new OrderItem { ItemId = "abcd123", Quantity = 1 },
                    new OrderItem { ItemId = "fghi456", Quantity = 2 }
                }
            };

            //多参数集合初始化器,它添加元素的方法是 Add(key, value)
            var releaseYears = new Dictionary<string, int>
            {
                { "Please please me", 1963 },
                { "Revolver", 1966 },
                { "Sgt. Pepper's Lonely Hearts Club Band", 1967 },
                { "Abbey Road", 1970 }
            };
        }
    }

    public class Order
    {
        private readonly List<OrderItem> items = new List<OrderItem>();
        public string OrderId { get; set; }
        public Customer Customer { get; set; }
        public List<OrderItem> Items { get { return items; } }
    }
    public class OrderItem
    {
        public string ItemId { get; set; }
        public int Quantity { get; set; }
    }
    public class Customer
    {
        public string Name { get; set; }
        public string Address { get; set; }
    }
    #endregion

    
}
